import lxml.etree as le

with open('csdn_edu.html','r',encoding='utf-8') as f: #打开文件
    html = f.read() # 读取文件
    html_s = le.HTML(html) #转换成为xpath可读取对象
    div_x_s = html_s.xpath('//div[@class="classify_cList"]')
    data_s = []
    for div_x in div_x_s:
        category1 = div_x.xpath('./h3/a/text()')[0]
        category2_s = div_x.xpath('./div/span/a/text()')
        data_s.append(
            dict(
                category1 = category1,
                category2_s = category2_s
            )
        )
    print(data_s)
    for data in data_s:
        print(data.get('category1'))
        for category2 in category2_s:
            print('     ',category2)
